﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using EvacuationWidth.Properties;
using YJKRGeometry;
using ModelCheckUtility;
using ModelCheckUtility.ModelLayer;

namespace EvacuationWidth.ModelLayer
{
	public class RoomPacker_EvacuationWidth : BaseRoomPacker, IAdaptPacker
	{
		internal List<DoorPacker_EvacuationWidth> LstAllDoors
		{
			get
			{
				return this.m_lstAllDoors;
			}
			private set
			{
				this.m_lstAllDoors = value;
			}
		}

		internal List<HostInRoomPacker_EvacuationWidth> LstAllHostInRoomPackers
		{
			get
			{
				return this.m_lstAllHostInRoomPackers;
			}
			private set
			{
				this.m_lstAllHostInRoomPackers = value;
			}
		}

		public double ChairsNumber
		{
			get
			{
				return this.m_nChairsNumber;
			}
			private set
			{
				this.m_nChairsNumber = value;
			}
		}

		public double TotalStairsWidth
		{
			get
			{
				return this.m_dTotalStairsWidth;
			}
			private set
			{
				this.m_dTotalStairsWidth = value;
			}
		}

		public RoomPacker_EvacuationWidth(Room inputValue, RevitLinkInstance useLinkInstance = null) : base(inputValue, useLinkInstance)
		{
		}

		public void AdaptThisPacker()
		{
			this.LstAllDoors = new List<DoorPacker_EvacuationWidth>();
			foreach (BaseDoorPacker baseDoorPacker in base.LstBaseDoorPacker)
			{
				if (baseDoorPacker is DoorPacker_EvacuationWidth && baseDoorPacker != null)
				{
					this.LstAllDoors.Add(baseDoorPacker as DoorPacker_EvacuationWidth);
				}
			}
			this.LstAllHostInRoomPackers = new List<HostInRoomPacker_EvacuationWidth>();
			foreach (KeyValuePair<BaseHostInRoomPacker, XYZ> keyValuePair in base.LstHostElementPacker)
			{
				if (keyValuePair.Key is HostInRoomPacker_EvacuationWidth && keyValuePair.Key != null)
				{
					HostInRoomPacker_EvacuationWidth hostInRoomPacker_EvacuationWidth = keyValuePair.Key as HostInRoomPacker_EvacuationWidth;
					this.LstAllHostInRoomPackers.Add(hostInRoomPacker_EvacuationWidth);
					if (hostInRoomPacker_EvacuationWidth.IfIsChair)
					{
						this.ChairsNumber += 1.0;
					}
					else if (hostInRoomPacker_EvacuationWidth.IfIsStair && hostInRoomPacker_EvacuationWidth.IfGetStairWidthSucess)
					{
						this.m_dTotalStairsWidth += hostInRoomPacker_EvacuationWidth.StairsWidth;
					}
				}
			}
		}

		internal bool TryGetPeopleDensity(out double peopleDensity)
		{
			string empty = string.Empty;
            bool flag = ModelCheckUtility.Utility.TryGetEnityValue<double>(base.ThisRoom, Resources.Str_GuidOfRoomAddValue, Resources.Str_RoomAddValueRegionName, out peopleDensity);
			return flag && !Geometry.IsEqual(peopleDensity, 0.0);
		}

		private double m_nChairsNumber;

		private double m_dTotalStairsWidth;

		private List<DoorPacker_EvacuationWidth> m_lstAllDoors = new List<DoorPacker_EvacuationWidth>();

		private List<HostInRoomPacker_EvacuationWidth> m_lstAllHostInRoomPackers = new List<HostInRoomPacker_EvacuationWidth>();
	}
}
